package com.jcark.utilscode.listener

import android.view.View

/**
 * Description: 防按钮抖动（每次点击都更新最后点击时间，强制间隔指定时间）<br>
 * @author King.Zi<br>
 * @date 2022/7/14<br>
 * Email: 78688689@qq.com
 */
abstract class DebounceClickListener : View.OnClickListener {

    private var mLastClickTime: Long = 0
    var delayTime = 500L

    override fun onClick(v: View) {
        val currentTime: Long = System.currentTimeMillis()
        if (currentTime - mLastClickTime > delayTime) {
            onViewClick(v)
        }
        mLastClickTime = currentTime
    }

    protected abstract fun onViewClick(v: View)
}